home *** CD-ROM | disk | FTP | other *** search
/ Aminet 4 / Aminet 4 - November 1994.iso / aminet / dev / c / cweb31p9d.lha / CWeb / common.ch < prev    next >
Text File  |  1994-07-08  |  62KB  |  1,820 lines

  1.                                 -*-Web-*-
  2. This file, COMMON.CH, is part of CWEB.
  3. It is a changefile for COMMON.W, Version 3.1.
  4.  
  5. Authors and Contributors:
  6. (H2B) Hans-Hermann Bode, Universität Osnabrück,
  7.   (hhbode@@dosuni1.rz.uni-osnabrueck.de or HHBODE@@DOSUNI1.BITNET).
  8.  
  9. (KG) Klaus Guntermann, TH Darmstadt,
  10.   (guntermann@@iti.informatik.th-darmstadt.de).
  11.  
  12. (AS) Andreas Scherer,
  13.   Abt-Wolf-Straße 17, 96215 Lichtenfels, Germany.
  14.  
  15. (CS) Carsten Steger, Universität München,
  16.   carsten.steger@@informatik.tu-muenchen.de
  17.  
  18. (TW) Tomas Willis
  19.   tomas@@cae.wisc.edu
  20.  
  21. Caveat utilitor:  Some of the source code introduced by this change file is
  22. made conditional to the use of specific compilers on specific systems.
  23. This applies to places marked with `#ifdef __TURBOC__' and `#ifdef _AMIGA'.
  24.  
  25. This program is distributed WITHOUT ANY WARRANTY, express or implied.
  26.  
  27. The following copyright notice extends to this changefile only, not to
  28. the masterfile COMMON.W.
  29.  
  30. Copyright (C) 1993,1994 Andreas Scherer
  31. Copyright (C) 1991,1993 Carsten Steger
  32. Copyright (C) 1991-1993 Hans-Hermann Bode
  33.  
  34. Permission is granted to make and distribute verbatim copies of this
  35. document provided that the copyright notice and this permission notice
  36. are preserved on all copies.
  37.  
  38. Permission is granted to copy and distribute modified versions of this
  39. document under the conditions for verbatim copying, provided that the
  40. entire resulting derived work is distributed under the terms of a
  41. permission notice identical to this one.
  42.  
  43. Version history:
  44.  
  45. Version    Date        Author    Comment
  46. a1/t1    10 Oct 1991    H2B    First attempt for COMMON.W 2.0.
  47. p2    13 Feb 1992    H2B    Updated for COMMON.W 2.1, ANSI and Turbo
  48.                 changefiles merged together.
  49. p3    16 Apr 1992    H2B    Updated for COMMON.W 2.2, change option for
  50.                 |@@i| completed.
  51. p4    22 Jun 1992    H2B    Updated for COMMON.W 2.4, getting INCLUDEDIR
  52.                 from environment variable CWEBINCLUDE.
  53. p5    19 Jul 1992    H2B    string.h included, usage message extended.
  54. p5a    24 Jul 1992    KG    adaptions for other ANSI C compiler
  55. p5b    28 Jul 1992    H2B    Remaining headers converted to ANSI style.
  56. p5c    30 Jul 1992    KG    removed comments used after #endif
  57. p6    06 Sep 1992    H2B    Updated for COMMON.W 2.7.
  58. p6a     15 Mar 1993     AS      adaptions for SAS/C 6.0 compiler
  59. p6b     28 Jul 1993     AS      path delimiters are `/' or `:' for AMIGA
  60.     31 Aug 1993    AS    return codes extended to AMIGA values
  61. p6c    04 Sep 1993    AS    path searching with CWEBINCLUDE
  62. p6d    09 Oct 1993    AS    Updated for COMMON.W 2.8. (This was p7 for me)
  63. p7    06 Nov 1992    H2B    Converted to master change file, updated for
  64.                 common.w 2.8. [Not released.]
  65. p7.5    29 Nov 1992    H2B    Updated for COMMON.W 2.9beta. [Not released.]
  66. p8    04 Dec 1992    H2B    Updated for COMMON.W 2.9++ (stuff went into
  67.                 the source file). [Not released.]
  68. p8a    10 Mar 1993    H2B    Restructured for public release.
  69.                 [Not released.]
  70. p8b    15 Apr 1993    H2B    Updated for COMMON.W 3.0beta. [Not released.]
  71. p8c    21 Jun 1993    H2B    Updated for final COMMON.W 3.0.
  72. p8d    26 Oct 1993    AS    Incorporated with AMIGA version 2.8 [p7] and
  73.                 updated to version 3.0.
  74. p8e    04 Nov 1993    AS    Minor bugs fixed for UNIX and GNU-C.
  75. p9    18 Nov 1993    AS    Updated for COMMON.W 3.1
  76. p9a    30 Nov 1993    AS    Minor changes and corrections.
  77. p9b    06 Dec 1993    AS    Multilinguality implemented.
  78.     07 Dec 1993    AS    Fixed an obvious portability problem.
  79. p9c    18 Jan 1994    AS    Version information included.
  80.     25 Mar 1994    AS    Special `wrap_up' for Borland C.
  81. p9d    13 May 1994    AS    Dynamic memory allocation.
  82.     24 Jun 1994    AS    ARexx support for error-handling
  83.     02 Jul 1994    AS    Portability version.
  84. ------------------------------------------------------------------------------
  85. @x l.1
  86. % This file is part of CWEB.
  87. % This program by Silvio Levy and Donald E. Knuth
  88. % is based on a program by Knuth.
  89. % It is distributed WITHOUT ANY WARRANTY, express or implied.
  90. % Version 3.1 --- November 1993
  91.  
  92. % Copyright (C) 1987,1990,1993 Silvio Levy and Donald E. Knuth
  93. @y
  94. % This file, common.w, is part of CWEB.
  95. % This program by Silvio Levy and Donald E. Knuth
  96. % is based on a program by Knuth.
  97. % It is distributed WITHOUT ANY WARRANTY, express or implied.
  98. % Version 2.4 --- Don Knuth, June 1992
  99. % Version 2.4 [p5] --- Hans-Hermann Bode, July 1992
  100. % Version 2.4 [p5a] --- Klaus Guntermann, July 1992
  101. % Version 2.4 [p5b] --- Hans-Hermann Bode, July 1992
  102. % Version 2.4 [p5c] --- Klaus Guntermann, July 1992
  103. % Version 2.7 [p6] --- Hans-Hermann Bode, September 1992
  104. % Version 2.7 [p6a] --- Andreas Scherer, March 1993
  105. % Version 2.7 [p6b] --- Andreas Scherer, August 1993
  106. % Version 2.7 [p6c] --- Andreas Scherer, September 1993
  107. % Version 2.8 --- Don Knuth, June 1992
  108. % Version 2.8 [p7] --- Andreas Scherer, October 1993
  109. % Version 3.0 --- Don Knuth, June 1993
  110. % Version 3.0 [p8c] --- Hans-Hermann Bode, June 1993
  111. % Version 3.0 [p8d] --- Andreas Scherer, October 1993
  112. % Version 3.0 [p8e] --- Andreas Scherer, November 1993
  113. % Version 3.1 --- Don Knuth, November 1993
  114. % Version 3.1 [p9] --- Andreas Scherer, November 1993
  115. % Version 3.1 [p9a] --- Andreas Scherer, November 1993
  116. % Version 3.1 [p9b] --- Andreas Scherer, December 1993
  117. % Version 3.1 [p9c] --- Andreas Scherer, January 1994
  118. % Version 3.1 [p9d] --- Andreas Scherer, July 1994
  119.  
  120. % Copyright (C) 1987,1990,1993 Silvio Levy and Donald E. Knuth
  121. % Copyright (C) 1991-1993 Hans-Hermann Bode
  122. % Copyright (C) 1991,1993 Carsten Steger
  123. % Copyright (C) 1993,1994 Andreas Scherer
  124. @z
  125. ------------------------------------------------------------------------------
  126. @x l.20
  127. \def\title{Common code for CTANGLE and CWEAVE (Version 3.1)}
  128. @y
  129. \def\title{Common code for CTANGLE and CWEAVE (Version 3.1 [p9d])}
  130. @z
  131. ------------------------------------------------------------------------------
  132. @x l.25
  133.   \centerline{(Version 3.1)}
  134. @y
  135.   \centerline{(Version 3.1 [p9d])}
  136. @z
  137. ------------------------------------------------------------------------------
  138. @x l.29
  139. Copyright \copyright\ 1987, 1990, 1993 Silvio Levy and Donald E. Knuth
  140. @y
  141. Copyright \copyright\ 1987, 1990, 1993 Silvio Levy and Donald E. Knuth
  142. \smallskip\noindent
  143. Copyright \copyright\ 1991--1993 Hans-Hermann Bode
  144. \smallskip\noindent
  145. Copyright \copyright\ 1991, 1993 Carsten Steger
  146. \smallskip\noindent
  147. Copyright \copyright\ 1993, 1994 Andreas Scherer
  148. @z
  149. ------------------------------------------------------------------------------
  150. Activate this, if only the changed modules should be printed.
  151. x l.43
  152. \let\maybe=\iftrue
  153. y
  154. \let\maybe=\iffalse
  155. z
  156. ------------------------------------------------------------------------------
  157. PORTABILITY
  158. @x l.58
  159. @<Include files@>@/
  160. @y
  161. @<Include files@>@/
  162. @<Macro definitions@>@/
  163. @z
  164. ------------------------------------------------------------------------------
  165. ANSI, TRANSLATION
  166. @x l.89
  167. void
  168. common_init()
  169. {
  170.   @<Initialize pointers@>;
  171.   @<Set the default options common to \.{CTANGLE} and \.{CWEAVE}@>;
  172.   @<Scan arguments and open output files@>;
  173. }
  174. @y
  175. void common_init(void)
  176. {
  177.   @<Initialize pointers@>;
  178.   @<Use catalog translations@>;
  179.   @<Set the default options common to \.{CTANGLE} and \.{CWEAVE}@>;
  180.   @<Scan arguments and open output files@>;
  181. }
  182. @z
  183. ------------------------------------------------------------------------------
  184. @x l.108
  185. character set can type things like \.{\char'32} and \.{char'4} instead
  186. @y
  187. character set can type things like \.{\char'32} and \.{\char'4} instead
  188. @z
  189. ------------------------------------------------------------------------------
  190. MEMORY ALLOCATION
  191. @x l.158
  192. char buffer[long_buf_size]; /* where each line of input goes */
  193. char *buffer_end=buffer+buf_size-2; /* end of |buffer| */
  194. char *limit=buffer; /* points to the last character in the buffer */
  195. char *loc=buffer; /* points to the next character to be read from the buffer */
  196. @y
  197. char *buffer; /* where each line of input goes */
  198. char *buffer_end; /* end of |buffer| */
  199. char *limit; /* points to the last character in the buffer */
  200. char *loc; /* points to the next character to be read from the buffer */
  201. @z
  202. ------------------------------------------------------------------------------
  203. ANSI
  204. @x l.171
  205. int input_ln(fp) /* copies a line into |buffer| or returns 0 */
  206. FILE *fp; /* what file to read from */
  207. @y
  208. static int input_ln(FILE *fp) /* copies a line into |buffer| or returns 0 */
  209. /* |fp|: what file to read from */
  210. @z
  211. ------------------------------------------------------------------------------
  212. TRANSLATION
  213. @x l.182
  214.       ungetc(c,fp); loc=buffer; err_print("! Input line too long");
  215. @y
  216.       ungetc(c,fp); loc=buffer; err_print(get_string(MSG_ERROR_CO9));
  217. @z
  218. ------------------------------------------------------------------------------
  219. PORTABILITY
  220. @x l.205
  221. @d max_file_name_length 60
  222. @y
  223. @d max_file_name_length 256
  224. @z
  225. ------------------------------------------------------------------------------
  226. MEMORY ALLOCATION
  227. @x l.214
  228. FILE *file[max_include_depth]; /* stack of non-change files */
  229. FILE *change_file; /* change file */
  230. char file_name[max_include_depth][max_file_name_length];
  231.   /* stack of non-change file names */
  232. char change_file_name[max_file_name_length]; /* name of change file */
  233. char alt_web_file_name[max_file_name_length]; /* alternate name to try */
  234. int line[max_include_depth]; /* number of current line in the stacked files */
  235. @y
  236. FILE **file; /* stack of non-change files */
  237. FILE *change_file; /* change file */
  238. char **file_name; /* stack of non-change file names */
  239. char *change_file_name; /* name of change file */
  240. char *alt_web_file_name; /* alternate name to try */
  241. int *line; /* number of current line in the stacked files */
  242. @z
  243. ------------------------------------------------------------------------------
  244. ANSI
  245. @x l.235
  246. @d lines_dont_match (change_limit-change_buffer != limit-buffer ||
  247.   strncmp(buffer, change_buffer, limit-buffer))
  248. @y
  249. @d lines_dont_match (change_limit-change_buffer != limit-buffer || @|
  250.   strncmp(buffer, change_buffer, (size_t)(limit-buffer)))
  251. @z
  252. ------------------------------------------------------------------------------
  253. MEMORY ALLOCATION
  254. @x l.239
  255. char change_buffer[buf_size]; /* next line of |change_file| */
  256. @y
  257. char *change_buffer; /* next line of |change_file| */
  258. @z
  259. ------------------------------------------------------------------------------
  260. ANSI
  261. @x l.250
  262. void
  263. prime_the_change_buffer()
  264. @y
  265. static void prime_the_change_buffer(void)
  266. @z
  267. ------------------------------------------------------------------------------
  268. TRANSLATION
  269. @x l.273
  270.     err_print("! Missing @@x in change file");
  271. @y
  272.     err_print(get_string(MSG_ERROR_CO13));
  273. @z
  274. ------------------------------------------------------------------------------
  275. TRANLSATION
  276. @x l.284
  277.     err_print("! Change file ended after @@x");
  278. @y
  279.     err_print(get_string(MSG_ERROR_CO14));
  280. @z
  281. ------------------------------------------------------------------------------
  282. ANSI
  283. @x l.292
  284.   change_limit=change_buffer-buffer+limit;
  285.   strncpy(change_buffer,buffer,limit-buffer+1);
  286. @y
  287.   change_limit=change_buffer+(ptrdiff_t)(limit-buffer);
  288.   strncpy(change_buffer,buffer,(size_t)(limit-buffer+1));
  289. @z
  290. ------------------------------------------------------------------------------
  291. ANSI
  292. @x l.319
  293. void
  294. check_change() /* switches to |change_file| if the buffers match */
  295. @y
  296. static void check_change(void) /* switches to |change_file| if the buffers match */
  297. @z
  298. ------------------------------------------------------------------------------
  299. TRANSLATION
  300. @x l.332
  301.       err_print("! Change file ended before @@y");
  302. @y
  303.       err_print(get_string(MSG_ERROR_CO16_1));
  304. @z
  305. ------------------------------------------------------------------------------
  306. TRANSLATION
  307. @x l.346
  308.         err_print("! CWEB file ended during a change");
  309. @y
  310.         err_print(get_string(MSG_ERROR_CO16_2));
  311. @z
  312. ------------------------------------------------------------------------------
  313. TRANSLATION
  314. @x l.358
  315.   loc=buffer+2; err_print("! Where is the matching @@y?");
  316. @y
  317.   loc=buffer+2; err_print(get_string(MSG_ERROR_CO17_1));
  318. @z
  319. ------------------------------------------------------------------------------
  320. TRANSLATION
  321. @x l.365
  322.     err_print("of the preceding lines failed to match");
  323. @y
  324.     err_print(get_string(MSG_ERROR_CO17_2));
  325. @z
  326. ------------------------------------------------------------------------------
  327. ANSI
  328. @x l.377
  329. void
  330. reset_input()
  331. @y
  332. void reset_input(void)
  333. @z
  334. ------------------------------------------------------------------------------
  335. TRANSLATION
  336. @x l.395
  337.        fatal("! Cannot open input file ", web_file_name);
  338. @y
  339.        fatal(get_string(MSG_FATAL_CO19_1), web_file_name);
  340. @z
  341. ------------------------------------------------------------------------------
  342. PORTABILITY, TRANSLATION
  343. Right after the web file was opened we set up communication with the AREXX
  344. port of the SAS/C++ 6.x message browser.  If `scmsg' is not yet running we
  345. start it in `rexxonly' mode (no window will appear) and initialize the
  346. compilation run with the (full) name of the web file.
  347. @x l.400
  348. if ((change_file=fopen(change_file_name,"r"))==NULL)
  349.        fatal("! Cannot open change file ", change_file_name);
  350. @y
  351. @<Set up the {\mc AREXX} communication@>@;
  352. if ((change_file=fopen(change_file_name,"r"))==NULL)
  353.        fatal(get_string(MSG_FATAL_CO19_2), change_file_name);
  354. @z
  355. ------------------------------------------------------------------------------
  356. ANSI
  357. @x l.417
  358. typedef unsigned short sixteen_bits;
  359. @y
  360. typedef unsigned char eight_bits;
  361. typedef unsigned short sixteen_bits;
  362. @z
  363. ------------------------------------------------------------------------------
  364. MEMORY ALLOCATION
  365. @x l.419
  366. boolean changed_section[max_sections]; /* is the section changed? */
  367. @y
  368. boolean *changed_section; /* is the section changed? */
  369. @z
  370. ------------------------------------------------------------------------------
  371. ANSI
  372. @x l.425
  373. int get_line() /* inputs the next line */
  374. @y
  375. int get_line(void) /* inputs the next line */
  376. @z
  377. ------------------------------------------------------------------------------
  378. TRANSLATION
  379. @x l.439
  380.       err_print("! Include file name not given");
  381. @y
  382.       err_print(get_string(MSG_ERROR_CO21_1));
  383. @z
  384. ------------------------------------------------------------------------------
  385. TRANSLATION
  386. @x l.444
  387.       err_print("! Too many nested includes");
  388. @y
  389.       err_print(get_string(MSG_ERROR_CO21_2));
  390. @z
  391. ------------------------------------------------------------------------------
  392. PORTABILITY, SYSTEM DEPENDENCIES, TRANSLATION
  393. We provide a multiple search path algorithm much like the C preprocessor.
  394. @x l.454
  395. @ When an \.{@@i} line is found in the |cur_file|, we must temporarily
  396. stop reading it and start reading from the named include file.  The
  397. \.{@@i} line should give a complete file name with or without
  398. double quotes.
  399. If the environment variable \.{CWEBINPUTS} is set, or if the compiler flag
  400. of the same name was defined at compile time,
  401. \.{CWEB} will look for include files in the directory thus named, if
  402. it cannot find them in the current directory.
  403. (Colon-separated paths are not supported.)
  404. The remainder of the \.{@@i} line after the file name is ignored.
  405.  
  406. @d too_long() {include_depth--;
  407.         err_print("! Include file name too long"); goto restart;}
  408.  
  409. @<Include...@>=
  410. #include <stdlib.h> /* declaration of |getenv| and |exit| */
  411. @y
  412. @ When an \.{@@i} line is found in the |cur_file|, we must temporarily
  413. stop reading it and start reading from the named include file.  The
  414. \.{@@i} line should give a complete file name with or without
  415. double quotes.  The remainder of the \.{@@i} line after the file name
  416. is ignored.  \.{CWEB} will look for include files in standard directories
  417. specified in the environment variable \.{CWEBINPUTS}. Multiple search paths
  418. can be specified by delimiting them with \.{PATH\_SEPARATOR}s.  The given
  419. file is searched for in the current directory first.  You also may include
  420. device names; these must have a \.{DEVICE\_SEPARATOR} as their rightmost
  421. character.  For other systems than the {\mc AMIGA} different settings may
  422. be needed.
  423. @^system dependencies@>
  424.  
  425. @d too_long() {include_depth--;
  426.         err_print(get_string(MSG_ERROR_CO22)); goto restart;}
  427.  
  428. @<Include...@>=
  429. #include <stdlib.h> /* declaration of |getenv| and |exit| */
  430. #include <stddef.h> /* type definition of |ptrdiff_t| */
  431. @#
  432. #ifdef _AMIGA
  433. #define PATH_SEPARATOR   ','
  434. #define DIR_SEPARATOR    '/'
  435. #define DEVICE_SEPARATOR ':'
  436. #else
  437. #ifdef __TURBOC__
  438. #define PATH_SEPARATOR   ';'
  439. #define DIR_SEPARATOR    '\\'
  440. #define DEVICE_SEPARATOR ':'
  441. #else
  442. #define PATH_SEPARATOR   ':'
  443. #define DIR_SEPARATOR    '/'
  444. #define DEVICE_SEPARATOR '/'
  445. #endif
  446. #endif
  447. @z
  448. ------------------------------------------------------------------------------
  449. PORTABILITY
  450. CWEB will perform a path search for `@i'nclude files along the environment
  451. variable CWEBINPUTS in case the given file can not be opened in the current
  452. directory or in the absolute path.  The single paths are delimited by
  453. PATH_SEPARATORs.
  454. @x l.485
  455.   kk=getenv("CWEBINPUTS");
  456.   if (kk!=NULL) {
  457.     if ((l=strlen(kk))>max_file_name_length-2) too_long();
  458.     strcpy(temp_file_name,kk);
  459.   }
  460.   else {
  461. #ifdef CWEBINPUTS
  462.     if ((l=strlen(CWEBINPUTS))>max_file_name_length-2) too_long();
  463.     strcpy(temp_file_name,CWEBINPUTS);
  464. #else
  465.     l=0;
  466. #endif /* |CWEBINPUTS| */
  467.   }
  468.   if (l>0) {
  469.     if (k+l+2>=cur_file_name_end)  too_long();
  470. @.Include file name ...@>
  471.     for (; k>= cur_file_name; k--) *(k+l+1)=*k;
  472.     strcpy(cur_file_name,temp_file_name);
  473.     cur_file_name[l]='/'; /* \UNIX/ pathname separator */
  474.     if ((cur_file=fopen(cur_file_name,"r"))!=NULL) {
  475.       cur_line=0; print_where=1;
  476.       goto restart; /* success */
  477.     }
  478.   }
  479. @y
  480.   if(0==set_path(include_path,getenv("CWEBINPUTS"))) {
  481.     include_depth--; goto restart; /* internal error */
  482.   }
  483.   path_prefix = include_path;
  484.   while(path_prefix) {
  485.     for(kk=temp_file_name, p=path_prefix, l=0;
  486.       p && *p && *p!=PATH_SEPARATOR;
  487.       *kk++ = *p++, l++);
  488.     if(path_prefix && *path_prefix && *path_prefix!=PATH_SEPARATOR && @|
  489.       *--p!=DEVICE_SEPARATOR && *p!=DIR_SEPARATOR) {
  490.       *kk++ = DIR_SEPARATOR; l++;
  491.     }
  492.     if(k+l+2>=cur_file_name_end) too_long(); /* emergency break */
  493.     strcpy(kk,cur_file_name);
  494.     if(cur_file = fopen(temp_file_name,"r")) {
  495.       cur_line=0; print_where=1; goto restart; /* success */
  496.     }
  497.     if(next_path_prefix = strchr(path_prefix,PATH_SEPARATOR))
  498.       path_prefix = next_path_prefix+1;
  499.     else break; /* no more paths to search; no file found */
  500.   }
  501. @z
  502. ------------------------------------------------------------------------------
  503. TRANSLATION
  504. @x l.509
  505.   include_depth--; err_print("! Cannot open include file"); goto restart;
  506. @y
  507.   include_depth--; err_print(get_string(MSG_ERROR_CO23)); goto restart;
  508. @z
  509. ------------------------------------------------------------------------------
  510. TRANSLATION
  511. @x l.532
  512.     err_print("! Change file ended without @@z");
  513. @y
  514.     err_print(get_string(MSG_ERROR_CO25_1));
  515. @z
  516. ------------------------------------------------------------------------------
  517. TRANSLATION
  518. @x l.548
  519.         err_print("! Where is the matching @@z?");
  520. @y
  521.         err_print(get_string(MSG_ERROR_CO25_2));
  522. @z
  523. ------------------------------------------------------------------------------
  524. ANSI
  525. @x l.562
  526. void
  527. check_complete(){
  528.   if (change_limit!=change_buffer) { /* |changing| is 0 */
  529.     strncpy(buffer,change_buffer,change_limit-change_buffer+1);
  530.     limit=buffer+(int)(change_limit-change_buffer);
  531. @y
  532. void check_complete(void) {
  533.   if (change_limit!=change_buffer) { /* |changing| is 0 */
  534.     strncpy(buffer,change_buffer,(size_t)(change_limit-change_buffer+1));
  535.     limit=buffer+(ptrdiff_t)(change_limit-change_buffer);
  536. @z
  537. ------------------------------------------------------------------------------
  538. TRANSLATION
  539. @x l.568
  540.     err_print("! Change file entry did not match");
  541. @y
  542.     err_print(get_string(MSG_ERROR_CO26));
  543. @z
  544. ------------------------------------------------------------------------------
  545. PORTABILITY
  546. @x l.588
  547.   char *byte_start; /* beginning of the name in |byte_mem| */
  548. @y
  549.   char HUGE *byte_start; /* beginning of the name in |byte_mem| */
  550. @z
  551. ------------------------------------------------------------------------------
  552. PORTABILITY, MEMORY ALLOCATION
  553. @x l.591
  554. typedef name_info *name_pointer; /* pointer into array of |name_info|s */
  555. char byte_mem[max_bytes]; /* characters of names */
  556. char *byte_mem_end = byte_mem+max_bytes-1; /* end of |byte_mem| */
  557. name_info name_dir[max_names]; /* information about names */
  558. name_pointer name_dir_end = name_dir+max_names-1; /* end of |name_dir| */
  559. @y
  560. typedef name_info HUGE *name_pointer; /* pointer into array of |name_info|s */
  561. char HUGE *byte_mem; /* characters of names */
  562. char HUGE *byte_mem_end; /* end of |byte_mem| */
  563. name_info HUGE *name_dir; /* information about names */
  564. name_pointer name_dir_end; /* end of |name_dir| */
  565. @z
  566. ------------------------------------------------------------------------------
  567. ANSI
  568. @x l.601
  569. @d length(c) (c+1)->byte_start-(c)->byte_start /* the length of a name */
  570. @y
  571. @d length(c) (size_t)((c+1)->byte_start-(c)->byte_start) /* the length of a name */
  572. @z
  573. ------------------------------------------------------------------------------
  574. PORTABILITY
  575. @x l.611
  576. char *byte_ptr; /* first unused position in |byte_mem| */
  577. @y
  578. char HUGE *byte_ptr; /* first unused position in |byte_mem| */
  579. @z
  580. ------------------------------------------------------------------------------
  581. MEMORY ALLOCATION, PORTABILITY, SYSTEM DEPENDENCIES, TRANSLATION
  582. @x l.613
  583. @ @<Init...@>=
  584. name_dir->byte_start=byte_ptr=byte_mem; /* position zero in both arrays */
  585. @y
  586. @ @f type int /* Aus \.{type} wird der Pseudotyp \&{type} */
  587. @#
  588. @d alloc_object(object,size,@!type)
  589.    if(!(object = (type *)calloc(size,sizeof(type))))
  590.       fatal("",get_string(MSG_FATAL_CO85));
  591.  
  592. @<Init...@>=
  593. alloc_object(buffer,long_buf_size,char);
  594. buffer_end = buffer + buf_size - 2;
  595. limit = loc = buffer;
  596. alloc_object(file,max_include_depth,FILE *);
  597. alloc_object(file_name,max_include_depth,char *);
  598. for(phase=0; phase<max_include_depth; phase++)
  599.   alloc_object(file_name[phase],max_file_name_length,char);
  600. alloc_object(change_file_name,max_file_name_length,char);
  601. alloc_object(alt_web_file_name,max_file_name_length,char);
  602. alloc_object(line,max_include_depth,int);
  603. alloc_object(change_buffer,buf_size,char);
  604. alloc_object(changed_section,max_sections,boolean);
  605. #ifdef __TURBOC__
  606. byte_mem=allocsafe(max_bytes,sizeof(*byte_mem));
  607. name_dir=allocsafe(max_names,sizeof(*name_dir));
  608. #else
  609. alloc_object(byte_mem,max_bytes,char);
  610. alloc_object(name_dir,max_names,name_info);
  611. #endif
  612. byte_mem_end = byte_mem + max_bytes - 1;
  613. name_dir_end = name_dir + max_names - 1;
  614. name_dir->byte_start=byte_ptr=byte_mem; /* position zero in both arrays */
  615. @^system dependencies@>
  616. @z
  617. ------------------------------------------------------------------------------
  618. PORTABILITY
  619. @x l.624
  620. struct name_info *link;
  621. @y
  622. struct name_info HUGE *link;
  623. @z
  624. ------------------------------------------------------------------------------
  625. MEMORY ALLOCATION
  626. @x l.638
  627. name_pointer hash[hash_size]; /* heads of hash lists */
  628. hash_pointer hash_end = hash+hash_size-1; /* end of |hash| */
  629. @y
  630. name_pointer *hash; /* heads of hash lists */
  631. hash_pointer hash_end; /* end of |hash| */
  632. @z
  633. ------------------------------------------------------------------------------
  634. ANSI
  635. @x l.642
  636. @ @<Predec...@>=
  637. extern int names_match();
  638. @y
  639. @ @<Predec...@>=
  640. extern int names_match(name_pointer,char *,int,eight_bits);@/
  641. @z
  642. ------------------------------------------------------------------------------
  643. MEMORY ALLOCATION
  644. @x l.647
  645. @<Init...@>=
  646. for (h=hash; h<=hash_end; *h++=NULL) ;
  647. @y
  648. @<Init...@>=
  649. alloc_object(hash,hash_size,name_pointer);
  650. hash_end = hash + hash_size - 1;
  651. for (h=hash; h<=hash_end; *h++=NULL) ;
  652. alloc_object(C_file_name,max_file_name_length,char);
  653. alloc_object(tex_file_name,max_file_name_length,char);
  654. alloc_object(idx_file_name,max_file_name_length,char);
  655. alloc_object(scn_file_name,max_file_name_length,char);
  656. @z
  657. ------------------------------------------------------------------------------
  658. ANSI
  659. @x l.653
  660. name_pointer
  661. id_lookup(first,last,t) /* looks up a string in the identifier table */
  662. char *first; /* first character of string */
  663. char *last; /* last character of string plus one */
  664. char t; /* the |ilk|; used by \.{CWEAVE} only */
  665. @y
  666. name_pointer id_lookup(char *first,char *last,char t)
  667. /* looks up a string in the identifier table */
  668. /* |first|: first character of string */
  669. /* |last|:  last character of string plus one */
  670. /* |t|:     the |ilk|; used by \.{CWEAVE} only */
  671. @z
  672. ------------------------------------------------------------------------------
  673. ANSI
  674. @x l.664
  675.   l=last-first; /* compute the length */
  676. @y
  677.   l=(int)(last-first); /* compute the length */
  678. @z
  679. ------------------------------------------------------------------------------
  680. ANSI
  681. @x l.695
  682. @<Pred...@>=
  683. void init_p();
  684. @y
  685. @<Pred...@>=
  686. extern void init_p(name_pointer,eight_bits);@/
  687. @z
  688. ------------------------------------------------------------------------------
  689. TRANSLATION
  690. @x l.699
  691.   if (byte_ptr+l>byte_mem_end) overflow("byte memory");
  692.   if (name_ptr>=name_dir_end) overflow("name");
  693. @y
  694.   if (byte_ptr+l>byte_mem_end) overflow(get_string(MSG_OVERFLOW_CO39_1));
  695.   if (name_ptr>=name_dir_end) overflow(get_string(MSG_OVERFLOW_CO39_2));
  696. @z
  697. ------------------------------------------------------------------------------
  698. PORTABILITY
  699. @x l.724
  700.   struct name_info *Rlink; /* right link in binary search tree for section
  701. @y
  702.   struct name_info HUGE *Rlink; /* right link in binary search tree for section
  703. @z
  704. ------------------------------------------------------------------------------
  705. ANSI
  706. @x l.757
  707. void
  708. print_section_name(p)
  709. name_pointer p;
  710. @y
  711. void print_section_name(name_pointer p)
  712. @z
  713. ------------------------------------------------------------------------------
  714. PORTABILITY
  715. @x l.761
  716.   char *ss, *s = first_chunk(p);
  717. @y
  718.   char HUGE *ss;
  719.   char HUGE *s = first_chunk(p);
  720. @z
  721. ------------------------------------------------------------------------------
  722. ANSI
  723. @x l.766
  724.       term_write(s,ss-s); p=q->link; q=p;
  725.     } else {
  726.       term_write(s,ss+1-s); p=name_dir; q=NULL;
  727. @y
  728.       term_write(s,(size_t)(ss-s)); p=q->link; q=p;
  729.     } else {
  730.       term_write(s,(size_t)(ss+1-s)); p=name_dir; q=NULL;
  731. @z
  732. ------------------------------------------------------------------------------
  733. ANSI
  734. @x l.776
  735. void
  736. sprint_section_name(dest,p)
  737.   char*dest;
  738.   name_pointer p;
  739. @y
  740. void sprint_section_name(char *dest,name_pointer p)
  741. @z
  742. ------------------------------------------------------------------------------
  743. PORTABILITY
  744. @x l.781
  745.   char *ss, *s = first_chunk(p);
  746. @y
  747.   char HUGE *ss;
  748.   char HUGE *s = first_chunk(p);
  749. @z
  750. ------------------------------------------------------------------------------
  751. ANSI
  752. @x l.790
  753.     strncpy(dest,s,ss-s), dest+=ss-s;
  754. @y
  755.     strncpy(dest,s,(size_t)(ss-s)), dest+=ss-s;
  756. @z
  757. ------------------------------------------------------------------------------
  758. ANSI
  759. @x l.797
  760. void
  761. print_prefix_name(p)
  762. name_pointer p;
  763. @y
  764. void print_prefix_name(name_pointer p)
  765. @z
  766. ------------------------------------------------------------------------------
  767. PORTABILITY
  768. @x l.801
  769.   char *s = first_chunk(p);
  770. @y
  771.   char HUGE *s = first_chunk(p);
  772. @z
  773. ------------------------------------------------------------------------------
  774. ANSI, PORTABILITY
  775. @x l.818
  776. int web_strcmp(j,j_len,k,k_len) /* fuller comparison than |strcmp| */
  777.   char *j, *k; /* beginning of first and second strings */
  778.   int j_len, k_len; /* length of strings */
  779. {
  780.   char *j1=j+j_len, *k1=k+k_len;
  781. @y
  782. static int web_strcmp(char HUGE *j, int j_len, char HUGE *k, int k_len)
  783.  /* fuller comparison than |strcmp| */
  784.  /* |j|: beginning of first string */
  785.  /* |k|: beginning of second string */
  786.  /* |j_len|: length of first string */
  787.  /* |k_len|: length of second string */
  788. {
  789.   char HUGE *j1=j+j_len;
  790.   char HUGE *k1=k+k_len;
  791. @z
  792. ------------------------------------------------------------------------------
  793. ANSI
  794. @x l.844
  795. @<Prede...@>=
  796. extern void init_node();
  797. @y
  798. @<Prede...@>=
  799. extern void init_node(name_pointer);@/
  800. @z
  801. ------------------------------------------------------------------------------
  802. ANSI
  803. @x l.848
  804. name_pointer
  805. add_section_name(par,c,first,last,ispref) /* install a new node in the tree */
  806. name_pointer par; /* parent of new node */
  807. int c; /* right or left? */
  808. char *first; /* first character of section name */
  809. char *last; /* last character of section name, plus one */
  810. int ispref; /* are we adding a prefix or a full name? */
  811. @y
  812. name_pointer add_section_name(name_pointer par, int c,
  813.   char *first, char *last, int ispref)
  814.   /* install a new node in the tree */
  815.   /* par: parent of new node */
  816.   /* c: right or left? */
  817.   /* first: first character of section name */
  818.   /* last: last character of section name, plus one */
  819.   /* ispref: are we adding a prefix or a full name? */
  820. @z
  821. ------------------------------------------------------------------------------
  822. ANSI, TRANSLATION
  823. @x l.857
  824.   char *s=first_chunk(p);
  825.   int name_len=last-first+ispref; /* length of section name */
  826.   if (s+name_len>byte_mem_end) overflow("byte memory");
  827.   if (name_ptr+1>=name_dir_end) overflow("name");
  828. @y
  829.   char HUGE *s=first_chunk(p);
  830.   int name_len=(int)(last-first)+ispref; /* length of section name */
  831.   if (s+name_len>byte_mem_end) overflow(get_string(MSG_OVERFLOW_CO39_1));
  832.   if (name_ptr+1>=name_dir_end) overflow(get_string(MSG_OVERFLOW_CO39_2));
  833. @z
  834. ------------------------------------------------------------------------------
  835. ANSI
  836. @x l.877
  837. void
  838. extend_section_name(p,first,last,ispref)
  839. name_pointer p; /* name to be extended */
  840. char *first; /* beginning of extension text */
  841. char *last; /* one beyond end of extension text */
  842. int ispref; /* are we adding a prefix or a full name? */
  843. @y
  844. void extend_section_name(name_pointer p,char *first,char *last,int ispref)
  845.   /* p: name to be extended */
  846.   /* first: beginning of extension text */
  847.   /* last: one beyond end of extension text */
  848.   /* ispref: are we adding a prefix or a full name? */
  849. @z
  850. ------------------------------------------------------------------------------
  851. ANSI, PORTABILITY, TRANSLATION
  852. @x l.884
  853.   char *s;
  854.   name_pointer q=p+1;
  855.   int name_len=last-first+ispref;
  856.   if (name_ptr>=name_dir_end) overflow("name");
  857. @y
  858.   char HUGE *s;
  859.   name_pointer q=p+1;
  860.   int name_len=(int)(last-first)+ispref;
  861.   if (name_ptr>=name_dir_end) overflow(get_string(MSG_OVERFLOW_CO39_2));
  862. @z
  863. ------------------------------------------------------------------------------
  864. TRANSLATION
  865. @x l.892
  866.   if (s+name_len>byte_mem_end) overflow("byte memory");
  867. @y
  868.   if (s+name_len>byte_mem_end) overflow(get_string(MSG_OVERFLOW_CO39_1));
  869. @z
  870. ------------------------------------------------------------------------------
  871. @x l.900
  872. its doesn't match an existing one. The new name is the string
  873. @y
  874. it doesn't match an existing one. The new name is the string
  875. @z
  876. ------------------------------------------------------------------------------
  877. ANSI
  878. @x l.905
  879. name_pointer
  880. section_lookup(first,last,ispref) /* find or install section name in tree */
  881. char *first, *last; /* first and last characters of new name */
  882. int ispref; /* is the new name a prefix or a full name? */
  883. @y
  884. name_pointer section_lookup(char *first,char *last,int ispref)
  885.   /* find or install section name in tree */
  886.   /* first, last: first and last characters of new name */
  887.   /* ispref: is the new name a prefix or a full name? */
  888. @z
  889. ------------------------------------------------------------------------------
  890. ANSI
  891. @x l.916
  892.   int name_len=last-first+1;
  893. @y
  894.   int name_len=(int)(last-first)+1;
  895. @z
  896. ------------------------------------------------------------------------------
  897. TRANSLATION
  898. @x l.937
  899.       printf("\n! Ambiguous prefix: matches <");
  900. @.Ambiguous prefix ... @>
  901.       print_prefix_name(p);
  902.       printf(">\n and <");
  903. @y
  904.       printf(get_string(MSG_ERROR_CO50_1));
  905. @.Ambiguous prefix ... @>
  906.       print_prefix_name(p);
  907.       printf(get_string(MSG_ERROR_CO50_2));
  908. @z
  909. ------------------------------------------------------------------------------
  910. TRANSLATION
  911. @x l.966
  912.       printf("\n! New name is a prefix of <");
  913. @y
  914.       printf(get_string(MSG_ERROR_CO52_1));
  915. @z
  916. ------------------------------------------------------------------------------
  917. TRANSLATION
  918. @x l.978
  919.       printf("\n! New name extends <");
  920. @y
  921.       printf(get_string(MSG_ERROR_CO52_2));
  922. @z
  923. ------------------------------------------------------------------------------
  924. TRANSLATION
  925. @x l.984
  926.     printf("\n! Section name incompatible with <");
  927. @.Section name incompatible...@>
  928.     print_prefix_name(r);
  929.     printf(">,\n which abbreviates <");
  930. @y
  931.     printf(get_string(MSG_ERROR_CO52_3));
  932. @.Section name incompatible...@>
  933.     print_prefix_name(r);
  934.     printf(get_string(MSG_ERROR_CO52_4));
  935. @z
  936. ------------------------------------------------------------------------------
  937. ANSI
  938. @x l.1009
  939. @<Predec...@>=
  940. int section_name_cmp();
  941. @y
  942. @<Predec...@>=
  943. static int section_name_cmp(char **,int,name_pointer);@/
  944. @z
  945. ------------------------------------------------------------------------------
  946. ANSI
  947. @x l.1013
  948. int section_name_cmp(pfirst,len,r)
  949. char **pfirst; /* pointer to beginning of comparison string */
  950. int len; /* length of string */
  951. name_pointer r; /* section name being compared */
  952. @y
  953. static int section_name_cmp(char **pfirst,int len,name_pointer r)
  954.   /*pfirst: pointer to beginning of comparison string */
  955.   /* len: length of string */
  956.   /* r: section name being compared */
  957. @z
  958. ------------------------------------------------------------------------------
  959. PORTABILITY
  960. @x l.1020
  961.   char *ss, *s=first_chunk(r);
  962. @y
  963.   char HUGE *ss;
  964.   char HUGE *s=first_chunk(r);
  965. @z
  966. ------------------------------------------------------------------------------
  967. ANSI
  968. @x l.1030
  969.           *pfirst=first+(ss-s);
  970. @y
  971.           *pfirst=first+(ptrdiff_t)(ss-s);
  972. @z
  973. ------------------------------------------------------------------------------
  974. ANSI
  975. @x l.1037
  976.       if (q!=name_dir) {len -= ss-s; s=q->byte_start; r=q; continue;}
  977. @y
  978.       if (q!=name_dir) {len -= (int)(ss-s); s=q->byte_start; r=q; continue;}
  979. @z
  980. ------------------------------------------------------------------------------
  981. ANSI, PORTABILITY
  982. @x l.1052
  983. |equiv_or_xref| as a pointer to a |char|.
  984.  
  985. @<More elements of |name...@>=
  986. char *equiv_or_xref; /* info corresponding to names */
  987. @y
  988. |equiv_or_xref| as a pointer to |void|.
  989.  
  990. @<More elements of |name...@>=
  991. void HUGE *equiv_or_xref; /* info corresponding to names */
  992. @z
  993. ------------------------------------------------------------------------------
  994. ANSI
  995. @x l.1082
  996. if the string begins with |"|"|.
  997.  
  998. @<Predecl...@>=
  999. void  err_print();
  1000. @y
  1001. if the string begins with |"!"|.
  1002.  
  1003. @<Predecl...@>=
  1004. extern void err_print(char *);@/
  1005. @z
  1006. ------------------------------------------------------------------------------
  1007. ANSI
  1008. @x l.1088
  1009. void
  1010. err_print(s) /* prints `\..' and location of error message */
  1011. char *s;
  1012. @y
  1013. void err_print(char *s) /* prints `\..' and location of error message */
  1014. @z
  1015. ------------------------------------------------------------------------------
  1016. PORTABILITY, TRANSLATION
  1017. @x l.1109
  1018. {if (changing && include_depth==change_depth)
  1019.   printf(". (l. %d of change file)\n", change_line);
  1020. else if (include_depth==0) printf(". (l. %d)\n", cur_line);
  1021.   else printf(". (l. %d of include file %s)\n", cur_line, cur_file_name);
  1022. @y
  1023. {if (changing && include_depth==change_depth) {
  1024.   printf(get_string(MSG_ERROR_CO59_1), change_line);
  1025.   @<Report an error in the change file@>@;
  1026.   }
  1027. else if (include_depth==0) {
  1028.   printf(get_string(MSG_ERROR_CO59_2), cur_line);
  1029.   @<Report an error in the web file@>@;
  1030.   }
  1031. else {
  1032.   printf(get_string(MSG_ERROR_CO59_3), cur_line, cur_file_name);
  1033.   @<Report an error in an include file@>@;
  1034.   }
  1035.  
  1036. @<Put the error message in the browser@>@;
  1037. @z
  1038. ------------------------------------------------------------------------------
  1039. ANSI
  1040. @x l.1132
  1041. @<Prede...@>=
  1042. int wrap_up();
  1043. extern void print_stats();
  1044. @y
  1045. @<Prede...@>=
  1046. extern int wrap_up(void);@/
  1047. extern void print_stats(void);@/
  1048. @z
  1049. ------------------------------------------------------------------------------
  1050. PORTABILITY, SYSTEM DEPENDENCIES, TRANSLATION
  1051. @x l.1136
  1052. @ Some implementations may wish to pass the |history| value to the
  1053. operating system so that it can be used to govern whether or not other
  1054. programs are started. Here, for instance, we pass the operating system
  1055. a status of 0 if and only if only harmless messages were printed.
  1056. @^system dependencies@>
  1057.  
  1058. @c
  1059. int wrap_up() {
  1060.   putchar('\n');
  1061.   if (show_stats)
  1062.     print_stats(); /* print statistics about memory usage */
  1063.   @<Print the job |history|@>;
  1064.   if (history > harmless_message) return(1);
  1065.   else return(0);
  1066. }
  1067. @y
  1068. @ On multi-tasking systems like the {\mc AMIGA} it is very convenient to know
  1069. a little bit more about the reasons why a program failed.  The four levels
  1070. of return indicated by the |history| value are very suitable for this
  1071. purpose.  Here, for instance, we pass the operating system a status of~0
  1072. if and only if the run was a complete success.  Any warning or error
  1073. message will result in a higher return value, so {\mc AREXX} scripts can be
  1074. made sensitive to these conditions.
  1075. @^system dependencies@>
  1076.  
  1077. @d RETURN_OK     0 /* No problems, success */
  1078. @d RETURN_WARN   5 /* A warning only */
  1079. @d RETURN_ERROR 10 /* Something wrong */
  1080. @d RETURN_FAIL  20 /* Complete or severe failure */
  1081.  
  1082. @c
  1083. #ifndef __TURBOC__
  1084. int wrap_up(void) {
  1085.   putchar('\n');
  1086.   if (show_stats) print_stats(); /* print statistics about memory usage */
  1087.   @<Print the job |history|@>;
  1088.   @<Close the language catalog@>;
  1089.   switch(history) {
  1090.   case harmless_message: return(RETURN_WARN); break;
  1091.   case error_message: return(RETURN_ERROR); break;
  1092.   case fatal_message: return(RETURN_FAIL); break;
  1093.   default: return(RETURN_OK);
  1094.     }
  1095.   }
  1096. #else
  1097. int wrap_up(void) {
  1098.   int return_val;
  1099.  
  1100.   putchar('\n');
  1101.   if (show_stats) print_stats(); /* print statistics about memory usage */
  1102.   @<Print the job |history|@>;
  1103.   @<Close the language catalog@>;
  1104.   switch(history) {
  1105.   case harmless_message: return_val=RETURN_WARN; break;
  1106.   case error_message: return_val=RETURN_ERROR; break;
  1107.   case fatal_message: return_val=RETURN_FAIL; break;
  1108.   default: return_val=RETURN_OK;
  1109.     }
  1110.   return(return_val);
  1111.   }
  1112. #endif
  1113. @z
  1114. ------------------------------------------------------------------------------
  1115. TRANSLATION
  1116. @x l.1154
  1117. case spotless: if (show_happiness) printf("(No errors were found.)\n"); break;
  1118. case harmless_message:
  1119.   printf("(Did you see the warning message above?)\n"); break;
  1120. case error_message:
  1121.   printf("(Pardon me, but I think I spotted something wrong.)\n"); break;
  1122. case fatal_message: printf("(That was a fatal error, my friend.)\n");
  1123. @y
  1124. case spotless:
  1125.   if (show_happiness) printf(get_string(MSG_HAPPINESS_CO62)); break;
  1126. case harmless_message:
  1127.   printf(get_string(MSG_WARNING_CO62)); break;
  1128. case error_message:
  1129.   printf(get_string(MSG_ERROR_CO62)); break;
  1130. case fatal_message:
  1131.   printf(get_string(MSG_FATAL_CO62));
  1132. @z
  1133. ------------------------------------------------------------------------------
  1134. ANSI
  1135. @x l.1165
  1136. @<Predec...@>=
  1137. void fatal(), overflow();
  1138. @y
  1139. @<Predec...@>=
  1140. extern void fatal(char *,char *);
  1141. extern void overflow(char *);
  1142. @z
  1143. ------------------------------------------------------------------------------
  1144. ANSI
  1145. @x l.1171
  1146. @c void
  1147. fatal(s,t)
  1148.   char *s,*t;
  1149. @y
  1150. @c void fatal(char *s,char *t)
  1151. @z
  1152. ------------------------------------------------------------------------------
  1153. ANSI
  1154. @x l.1182
  1155. @c void
  1156. overflow(t)
  1157.   char *t;
  1158. @y
  1159. @c void overflow(char *t)
  1160. @z
  1161. ------------------------------------------------------------------------------
  1162. TRANSLATION
  1163. @x l.1186
  1164.   printf("\n! Sorry, %s capacity exceeded",t); fatal("","");
  1165. @y
  1166.   printf(get_string(MSG_FATAL_CO65),t); fatal("","");
  1167. @z
  1168. ------------------------------------------------------------------------------
  1169. TRANSLATION
  1170. @x l.1195
  1171. @d confusion(s) fatal("! This can't happen: ",s)
  1172. @y
  1173. @d confusion(s) fatal(get_string(MSG_FATAL_CO66),s)
  1174. @z
  1175. ------------------------------------------------------------------------------
  1176. PORTABILITY
  1177. On the AMIGA there is a list of additional identifiers that have to be
  1178. formatted correctly.  We don't want to \.{@@i}nclude them for every AMIGA
  1179. program anew, so we provide an extension to CWEAVE.
  1180. For German programmers it is more convenient to write program documentations
  1181. in German instead of in English.  With the \.{+g} option German TeX macros
  1182. are included.
  1183. The original CWEAVE indents parameter declarations in old-style function
  1184. heads.  If you don't like this, you can typeset them flush left with \.{-i}.
  1185. The original CWEAVE puts extra white space after variable declarations and
  1186. before the first statement in a function block.  If you don't like this,
  1187. you can use the \.{-o} option.  This feature was already mentioned in the
  1188. original documentation, but it was not implemented.
  1189. This changes by Andreas Scherer are based on ideas by Carsten Steger
  1190. provided in his `CWeb 2.0' port from ><> 551 and his `CWeb 2.8' port
  1191. from the electronic nets.
  1192. @x l.1201
  1193. or flags to be turned on (beginning with |"+"|.
  1194. The following globals are for communicating the user's desires to the rest
  1195. of the program. The various file name variables contain strings with
  1196. the names of those files. Most of the 128 flags are undefined but available
  1197. for future extensions.
  1198.  
  1199. @d show_banner flags['b'] /* should the banner line be printed? */
  1200. @d show_progress flags['p'] /* should progress reports be printed? */
  1201. @d show_stats flags['s'] /* should statistics be printed at end of run? */
  1202. @d show_happiness flags['h'] /* should lack of errors be announced? */
  1203. @y
  1204. or flags to be turned on (beginning with |"+"|).
  1205. The following globals are for communicating the user's desires to the rest
  1206. of the program. The various file name variables contain strings with
  1207. the names of those files. Most of the 256 flags are undefined but available
  1208. for future extensions.
  1209.  
  1210. @d show_banner flags['b'] /* should the banner line be printed? */
  1211. @d show_progress flags['p'] /* should progress reports be printed? */
  1212. @d show_stats flags['s'] /* should statistics be printed at end of run? */
  1213. @d show_happiness flags['h'] /* should lack of errors be announced? */
  1214. @d use_amiga_keywords flags['a'] /* should {\mc AMIGA/SAS C} keywords be used? */
  1215. @d use_german_macros flags['g'] /* should the output be German? */
  1216. @d indent_param_decl flags['i'] /* should formal parameter declarations be indented? */
  1217. @d send_error_messages flags['m'] /* should {\mc AREXX} communication be used? */
  1218. @d order_decl_stmt flags['o'] /* should declarations and statements be separated? */
  1219. @z
  1220. ------------------------------------------------------------------------------
  1221. MEMORY ALLOCATION
  1222. @x l.1215
  1223. char C_file_name[max_file_name_length]; /* name of |C_file| */
  1224. char tex_file_name[max_file_name_length]; /* name of |tex_file| */
  1225. char idx_file_name[max_file_name_length]; /* name of |idx_file| */
  1226. char scn_file_name[max_file_name_length]; /* name of |scn_file| */
  1227. boolean flags[128]; /* an option for each 7-bit code */
  1228. @y
  1229. char *C_file_name; /* name of |C_file| */
  1230. char *tex_file_name; /* name of |tex_file| */
  1231. char *idx_file_name; /* name of |idx_file| */
  1232. char *scn_file_name; /* name of |scn_file| */
  1233. boolean flags[256]; /* an option for each 8-bit code */
  1234. @z
  1235. ------------------------------------------------------------------------------
  1236. PORTABILITY, SYSTEM DEPENDENCIES
  1237. @x l.1225
  1238. @<Set the default options common to \.{CTANGLE} and \.{CWEAVE}@>=
  1239. show_banner=show_happiness=show_progress=1;
  1240. @y
  1241. @<Set the default options common to \.{CTANGLE} and \.{CWEAVE}@>=
  1242. show_banner=show_happiness=show_progress=1;
  1243. #ifdef _AMIGA
  1244. use_amiga_keywords=
  1245. #endif
  1246. use_german_macros=indent_param_decl=order_decl_stmt=1;
  1247. @^system dependencies@>
  1248. @z
  1249. ------------------------------------------------------------------------------
  1250. PORTABILITY
  1251. @x l.1237
  1252. An omitted change file argument means that |"/dev/null"| should be used,
  1253. when no changes are desired.
  1254. @y
  1255. An omitted change file argument means that |"/dev/null"| or---on {\mc
  1256. MS-DOS} systems---|"nul"| or---on {\mc AMIGA} systems---|"NIL:"| should be
  1257. used, when no changes are desired.
  1258. @z
  1259. ------------------------------------------------------------------------------
  1260. ANSI
  1261. @x l.1243
  1262. @<Pred...@>=
  1263. void scan_args();
  1264. @y
  1265. @<Pred...@>=
  1266. static void scan_args(void);@/
  1267. @z
  1268. ------------------------------------------------------------------------------
  1269. ANSI
  1270. @x l.1247
  1271. void
  1272. scan_args()
  1273. @y
  1274. static void scan_args(void)
  1275. @z
  1276. ------------------------------------------------------------------------------
  1277. PORTABILITY, SYSTEM DEPENDENCIES
  1278. @x l.1261
  1279.       while (*s) {
  1280.         if (*s=='.') dot_pos=s++;
  1281.         else if (*s=='/') dot_pos=NULL,name_pos=++s;
  1282.         else s++;
  1283.       }
  1284. @y
  1285.       while (*s) {
  1286.         if (*s=='.') dot_pos=s++;
  1287. #ifdef _AMIGA
  1288.         else if ((*s==DIR_SEPARATOR) || (*s==DEVICE_SEPARATOR)) dot_pos=NULL,name_pos=++s;
  1289. #else
  1290.         else if (*s==DIR_SEPARATOR) dot_pos=NULL,name_pos=++s;
  1291. #endif
  1292.         else s++;
  1293.       }
  1294. @^system dependencies@>
  1295. @z
  1296. ------------------------------------------------------------------------------
  1297. PORTABILITY, SYSTEM DEPENDENCIES
  1298. @x l.1274
  1299.   if (found_change<=0) strcpy(change_file_name,"/dev/null");
  1300. @y
  1301. #if defined( _AMIGA )
  1302.   if (found_change<=0) strcpy(change_file_name,"NIL:");
  1303. #else
  1304. #if defined( __TURBOC__ )
  1305.   if (found_change<=0) strcpy(change_file_name,"nul");
  1306. #else
  1307.   if (found_change<=0) strcpy(change_file_name,"/dev/null");
  1308. #endif
  1309. #endif
  1310. @^system dependencies@>
  1311. @z
  1312. ------------------------------------------------------------------------------
  1313. TRANSLATION
  1314. @x l.1328
  1315.         fatal("! Output file name should end with .tex\n",*argv);
  1316. @y
  1317.         fatal(get_string(MSG_FATAL_CO73),*argv);
  1318. @z
  1319. ------------------------------------------------------------------------------
  1320. SYSTEM DEPENDENCIES, TRANSLATION
  1321. When called with no arguments CTANGLE and CWEAVE provide a list of options.
  1322. @x l.1351
  1323.   fatal(
  1324. "! Usage: ctangle [options] webfile[.w] [{changefile[.ch]|-} [outfile[.c]]]\n"
  1325.    ,"");
  1326. @.Usage:@>
  1327. else fatal(
  1328. "! Usage: cweave [options] webfile[.w] [{changefile[.ch]|-} [outfile[.tex]]]\n"
  1329.    ,"");
  1330. @y
  1331.   fatal(get_string(MSG_FATAL_CO75_1),"");
  1332. @.Usage:@>
  1333. #ifdef _AMIGA
  1334. else fatal(get_string(MSG_FATAL_CO75_2),"");
  1335. #else
  1336. else fatal(get_string(MSG_FATAL_CO75_3),"");
  1337. #endif
  1338. @^system dependencies@>
  1339. @z
  1340. ------------------------------------------------------------------------------
  1341. TRANSLATION
  1342. @x l.1360
  1343. @ @<Complain about arg...@>= fatal("! Filename too long\n", *argv);
  1344. @y
  1345. @ @<Complain about arg...@>= fatal(get_string(MSG_FATAL_CO76), *argv);
  1346. @z
  1347. ------------------------------------------------------------------------------
  1348. TRANSLATION
  1349. @x l.1377
  1350.     fatal("! Cannot open output file ", C_file_name);
  1351. @y
  1352.     fatal(get_string(MSG_FATAL_CO78), C_file_name);
  1353. @z
  1354. ------------------------------------------------------------------------------
  1355. TRANSLATION
  1356. @x l.1382
  1357.     fatal("! Cannot open output file ", tex_file_name);
  1358. @y
  1359.     fatal(get_string(MSG_FATAL_CO78), tex_file_name);
  1360. @z
  1361. ------------------------------------------------------------------------------
  1362. ANSI, PORTABILITY, SYSTEM DEPENDENCIES, TRANSLATION
  1363. The `standard' header files are.  Any compiler ignoring them is not.
  1364. @x l.1402
  1365. @ We predeclare several standard system functions here instead of including
  1366. their system header files, because the names of the header files are not as
  1367. standard as the names of the functions. (For example, some \CEE/ environments
  1368. have \.{<string.h>} where others have \.{<strings.h>}.)
  1369.  
  1370. @<Predecl...@>=
  1371. extern int strlen(); /* length of string */
  1372. extern int strcmp(); /* compare strings lexicographically */
  1373. extern char* strcpy(); /* copy one string to another */
  1374. extern int strncmp(); /* compare up to $n$ string characters */
  1375. extern char* strncpy(); /* copy up to $n$ string characters */
  1376.  
  1377. @** Index.
  1378. @y
  1379. @ For string handling we include the {\mc ANSI C} system header file instead
  1380. of predeclaring the standard system functions |strlen|, |strcmp|, |strcpy|,
  1381. |strncmp|, and |strncpy|.
  1382. @^system dependencies@>
  1383.  
  1384. @<Include...@>=
  1385. #include <string.h>
  1386.  
  1387. @** Path searching.  By default, \.{CTANGLE} and \.{CWEAVE} are looking
  1388. for include files along the path |CWEBINPUTS|.  By setting the environment
  1389. variable of the same name to a different search path that suits your
  1390. personal needs, you may override the default on startup.  The following
  1391. procedure copies the value of the environment variable (if any) to the
  1392. variable |include_path| used for path searching.
  1393.  
  1394. @c
  1395. static boolean set_path(char *ptr,char *override)
  1396. {
  1397.   if(override) {
  1398.     if(strlen(override) >= max_path_length) {
  1399.       err_print("! Include path too long"); return(0);
  1400. @.Include path too long@>
  1401.     }
  1402.     else strcpy(ptr, override);
  1403.   }
  1404.   return(1);
  1405. }
  1406.  
  1407. @ The path search algorithm defined in section |@<Try to open...@>|
  1408. needs a few extra variables.  If no string is given in this variable,
  1409. the internal default |CWEBINPUTS| is used instead, which holds some
  1410. sensible paths.
  1411. @^system dependencies@>
  1412.  
  1413. @d max_path_length 4095
  1414.  
  1415. @<Other...@>=
  1416. char *include_path;@/
  1417. char *p, *path_prefix, *next_path_prefix;@/
  1418.  
  1419. @ @<Init...@>=
  1420. alloc_object(include_path,max_path_length+1,char);
  1421. strcpy(include_path,CWEBINPUTS);
  1422.  
  1423. @** Memory allocation. Due to restrictions of most {\mc MS-DOS}-\CEE/ compilers,
  1424. large arrays will be allocated dynamically rather than statically. In the {\mc
  1425. TURBO}-\CEE/ implementation the |farcalloc| function provides a way to allocate
  1426. more than 64~KByte of data. The |allocsafe| function tries to carry out an
  1427. allocation of |nunits| blocks of size |unitsz| by calling |farcalloc| and takes
  1428. a safe method, when this fails: the program will be aborted.
  1429.  
  1430. To deal with such allocated data areas |huge| pointers will be used in this
  1431. implementation.
  1432.  
  1433. @f far int
  1434. @f huge int
  1435. @f HUGE int
  1436.  
  1437. @<Pred...@>=
  1438. #ifdef __TURBOC__
  1439. extern void far *allocsafe(unsigned long,unsigned long);
  1440. #endif
  1441. @^system dependencies@>
  1442.  
  1443. @ @c
  1444. #ifdef __TURBOC__
  1445. void far *allocsafe (unsigned long nunits,unsigned long unitsz)
  1446. {
  1447.   void far *p = farcalloc(nunits,unitsz);
  1448.   if (p==NULL) fatal("",get_string(MSG_FATAL_CO85));
  1449. @.Memory allocation failure@>
  1450.   return p;
  1451. }
  1452. #endif
  1453. @^system dependencies@>
  1454.  
  1455. @ @<Include...@>=
  1456. #ifdef __TURBOC__
  1457. #include <alloc.h> /* import |farcalloc| */
  1458. #include <io.h> /* import |write| */
  1459. #endif
  1460. @^system dependencies@>
  1461.  
  1462. @ @<Macro...@>=
  1463. #ifdef __TURBOC__
  1464. #define HUGE huge
  1465. #else
  1466. #define HUGE
  1467. #endif
  1468. @^system dependencies@>
  1469.  
  1470. @** Multilinguality.  The {\mc AMIGA} operating system (and maybe some
  1471. other operating systems as well), starting with version~2.1, is inherently
  1472. multilingual.  With the help of system catalogs, any decent program
  1473. interface can be made sensitive to the language the user wants to be
  1474. addressed with.  All terminal output strings were located and replaced by
  1475. references to an external array |AppStrings|.  The English defaults of
  1476. these strings can be overwritten by the entries of translated catalogs.
  1477. The following include file \.{cweb.h} contains a complete description of
  1478. all strings used in this extended \.{CWEB} system.
  1479. @^system dependencies@>
  1480.  
  1481. @<Include files@>=
  1482. #ifdef _AMIGA
  1483. #include <libraries/locale.h>
  1484. #include <proto/locale.h>
  1485. #include <proto/exec.h>
  1486. @#
  1487. struct Library *LocaleBase; /* pointer to the locale library */
  1488. struct Catalog *catalog; /* pointer to the external catalog */
  1489. int i; /* global counter for list of strings */
  1490. #else /* non-{\mc AMIGA} systems don't know about \.{<exec/types.h>} */
  1491. typedef long int LONG; /* excerpt from \.{<exec/types.h>} */
  1492. typedef char * STRPTR; /* ditto, but \UNIX/ says it's signed. */
  1493. #define EXEC_TYPES_H 1 /* don't include \.{<exec/types.h>} in \.{"cweb.h"} */
  1494. #endif
  1495. @#
  1496. #define STRINGARRAY 1 /* include the string array |AppStrings| for real */
  1497. #define get_string(n) AppStrings[n].as_Str /* reference string $n$ */
  1498. @#
  1499. #include "cweb.h"
  1500.  
  1501. @ Version~2.1 or higher of the {\mc AMIGA} operating system (represented as
  1502. internal version~38) will replace the complete set of terminal output strings
  1503. by an external translation in accordance to the system default language.
  1504. @^system dependencies@>
  1505.  
  1506. @<Use catalog translations@>=
  1507. #ifdef _AMIGA
  1508.   if(LocaleBase=OpenLibrary("locale.library",38L)) {
  1509.     if(catalog=OpenCatalog(NULL,"cweb.catalog",
  1510.       OC_BuiltInLanguage,"english",TAG_DONE)) {
  1511.       for(i=MSG_ERROR_CO9; i<=MSG_STATS_CW248_6; ++i)
  1512.         AppStrings[i].as_Str=GetCatalogStr(catalog,i,AppStrings[i].as_Str);
  1513.       }
  1514.     }
  1515. #endif
  1516.  
  1517. @ It is essential to close the pointer references to the language catalog
  1518. and to the system library before shutting down the program itself.
  1519. @^system dependencies@>
  1520.  
  1521. @<Close the language catalog@>=
  1522. #ifdef _AMIGA
  1523.   if(LocaleBase) {
  1524.     CloseCatalog(catalog);
  1525.     CloseLibrary(LocaleBase);
  1526.     }
  1527. #endif
  1528.  
  1529. @** AREXX communication.  In case of an error we want to have a common
  1530. interface used by \.{CWEB} and the \CEE/ compiler in the same way.  For
  1531. the {\mc AMIGA} this is \.{SCMSG}, the message browser of the {\mc SAS/C}
  1532. development system.  This program has an {\mc AREXX} port and can be
  1533. addressed by other applications like \.{CTANGLE} and \.{CWEAVE} with
  1534. the help of the routines described in this part.  (I admit to have
  1535. shamelessly borrowed code from the Pas\TEX/ implementation of
  1536. \.{dvips}~5.47 by Georg He{\ss}mann.)  To make use of this feature
  1537. it is necessary (besides having an {\mc AMIGA}) to include system
  1538. dependent header files.
  1539. @^system dependencies@>
  1540.  
  1541. @<Include files@>=
  1542. #ifdef _AMIGA
  1543. #include <exec/types.h>
  1544. #include <libraries/dos.h>
  1545. #include <clib/alib_protos.h>
  1546. #include <clib/exec_protos.h>
  1547. #include <clib/dos_protos.h>
  1548. #include <pragmas/exec_pragmas.h>
  1549. #include <pragmas/dos_pragmas.h>
  1550. @#
  1551. #include <string.h>
  1552. #include <dos.h>
  1553. @#
  1554. #include <rexx/rxslib.h>
  1555. #include <rexx/errors.h>
  1556. #endif
  1557.  
  1558. @ A list of declarations and variables is added.  Most of these are
  1559. globally defined because the initialization of the message port is done
  1560. outside these local routines.
  1561. @^system dependencies@>
  1562.  
  1563. @<Other...@>=
  1564. #ifdef _AMIGA
  1565. extern struct ExecBase *SysBase;
  1566. extern struct DOSBase *DOSBase;
  1567. @#
  1568. STRPTR          CreateArgstring(STRPTR, long);
  1569. void            DeleteArgstring(STRPTR);
  1570. struct RexxMsg  *CreateRexxMsg(struct MsgPort *, STRPTR, STRPTR);
  1571. void            DeleteRexxMsg(struct RexxMsg *);
  1572. @#
  1573. long result = 20;
  1574. char msg_string[BUFSIZ];
  1575. char pth_buffer[BUFSIZ];
  1576. char cur_buffer[BUFSIZ];
  1577. @#
  1578. struct RexxMsg *rm;
  1579. struct MsgPort *rp;
  1580. @#
  1581. @=#pragma libcall RexxSysBase CreateArgstring 7e 0802@>@;
  1582. @=#pragma libcall RexxSysBase DeleteArgstring 84 801@>@;
  1583. @=#pragma libcall RexxSysBase CreateRexxMsg   90 09803@>@;
  1584. @=#pragma libcall RexxSysBase DeleteRexxMsg   96 801@>@;
  1585. @#
  1586. #define MSGPORT  "SC_SCMSG"
  1587. #define PORTNAME "CWEBPORT"
  1588. #define RXEXTENS "rexx"
  1589. @#
  1590. struct RxsLib *RexxSysBase = NULL;
  1591. #endif
  1592.  
  1593. @ This function addresses the message browser of the {\mc SAS/C} system by
  1594. means of its {\mc AREXX} communication port.
  1595. @^system dependencies@>
  1596.  
  1597. @c
  1598. #ifdef _AMIGA
  1599. static int PutRexxMsg(struct MsgPort *mp, long action, STRPTR arg0,
  1600.   struct RexxMsg *arg1)
  1601.   {
  1602.   if ((rm = CreateRexxMsg(mp, RXEXTENS, mp->mp_Node.ln_Name)) != NULL) {
  1603.     rm->rm_Action  = action;
  1604.     rm->rm_Args[0] = arg0;
  1605.     rm->rm_Args[1] = (STRPTR)arg1;
  1606.  
  1607.     Forbid(); /* Disable multitasking. */
  1608.     if ((rp = FindPort(MSGPORT)) != NULL)
  1609.       PutMsg(rp, (struct Message *)rm);
  1610.     Permit(); /* Enable multitasking. */
  1611.  
  1612.     if (rp == NULL) /* Sorry, message browser not found. */
  1613.       DeleteRexxMsg(rm);
  1614.   }
  1615.   return(rm != NULL && rp != NULL);
  1616. }
  1617. #endif
  1618.  
  1619. @ This function is the ``interface'' between \.{CWEB} and {\mc AREXX}\null.
  1620. The first argument is a string containing a full line of text to be sent to
  1621. the browser.  The second argument returns the transmission result.
  1622. @^system dependencies@>
  1623.  
  1624. @c
  1625. #ifdef _AMIGA
  1626. int __stdargs call_rexx(char *str, long *result)
  1627. {
  1628.   char *arg;
  1629.   struct MsgPort *mp;
  1630.   struct RexxMsg *rm, *rm2;
  1631.   int ret = FALSE;
  1632.   int pend;
  1633.  
  1634.   if (!(RexxSysBase = (struct RxsLib *)OpenLibrary(RXSNAME, 0)))
  1635.     return(ret);
  1636.  
  1637.   Forbid(); /* Disable multitasking. */
  1638.   if (FindPort(PORTNAME) == NULL)
  1639.     mp = CreatePort(PORTNAME, 0);
  1640.   Permit(); /* Enable multitasking. */
  1641.  
  1642.   if (mp != NULL) {
  1643.     if ((arg = CreateArgstring(str, strlen(str))) != NULL) {
  1644.       if (PutRexxMsg(mp, RXCOMM | RXFF_STRING, arg, NULL)) {
  1645.  
  1646.         for (pend = 1; pend != 0; )
  1647.           if (WaitPort(mp) != NULL)
  1648.             while ((rm = (struct RexxMsg *)GetMsg(mp)) != NULL)
  1649.               if (rm->rm_Node.mn_Node.ln_Type == NT_REPLYMSG) {
  1650.                 ret = TRUE;
  1651.                 *result = rm->rm_Result1;
  1652.                 if ((rm2 = (struct RexxMsg *)rm->rm_Args[1]) != NULL) {
  1653.                   rm2->rm_Result1 = rm->rm_Result1;
  1654.                   rm2->rm_Result2 = 0;
  1655.                   ReplyMsg((struct Message *)rm2);
  1656.                 }
  1657.                 DeleteRexxMsg(rm);
  1658.                 pend--;
  1659.               }
  1660.               else {
  1661.                 rm->rm_Result2 = 0;
  1662.                 if (PutRexxMsg(mp, rm->rm_Action, rm->rm_Args[0], rm))
  1663.                   pend++;
  1664.                 else {
  1665.                   rm->rm_Result1 = RC_FATAL;
  1666.                   ReplyMsg((struct Message *)rm);
  1667.                 }
  1668.               }
  1669.       }
  1670.       DeleteArgstring(arg);
  1671.     }
  1672.     DeletePort(mp);
  1673.   }
  1674.  
  1675.   CloseLibrary((struct Library *)RexxSysBase);
  1676.  
  1677.   return(ret);
  1678. }
  1679. #endif
  1680.  
  1681. @ The prototypes for these two new functions are added to the common list.
  1682. @^system dependencies@>
  1683.  
  1684. @<Predecl...@>=
  1685. #ifdef _AMIGA
  1686. static int PutRexxMsg(struct MsgPort *,long,STRPTR,struct RexxMsg *);
  1687. int __stdargs call_rexx(char *,long *);
  1688. #endif
  1689.  
  1690. @ Before we can send any signal to the message browser we have to make sure
  1691. that the receiving port is active.  Possibly a call to \.{scmsg} will
  1692. suffice.  If it is not there, any attempt to send a message will fail.
  1693.  
  1694. You can control the behaviour of \.{scmsg} via the external environment
  1695. variable \.{SCMSGOPT} which may contain any legal command line options as
  1696. described in the documentation provided by {\mc SAS}~Institute.
  1697. The display window with the error messages will not appear if you supply
  1698. \.{scmsg} with its \.{rexxonly} option.  If you want to see every message
  1699. on your screen, replace this option with \.{hidden}.  The first error
  1700. message received by \.{scmsg} will open the output window.  The very first
  1701. message for the browser initializes its database for the current web file.
  1702. Any pending entries will be destroyed before new ones are added.
  1703. @^system dependencies@>
  1704.  
  1705. @<Set up the {\mc AREXX} communication@>=
  1706. #ifdef _AMIGA
  1707. if(send_error_messages) {
  1708.   Forbid(); /* Disable multitasking. */
  1709.   if ((rp = FindPort(MSGPORT)) != NULL); /* Check for browser port. */
  1710.   Permit(); /* Enable multitasking. */
  1711.  
  1712.   if(!rp) { /* Make sure, the browser is active. */
  1713.     strcpy(msg_string,"run <nil: >nil: scmsg ");
  1714.     strcat(msg_string,getenv("SCMSGOPT")); /* Add browser options. */
  1715.     system(msg_string);
  1716.     }
  1717.  
  1718.   if(GetCurrentDirName(cur_buffer,BUFSIZ) && @|
  1719.     AddPart(cur_buffer,web_file_name,BUFSIZ)) {
  1720.     sprintf(msg_string,"newbld \"%s\"",cur_buffer);
  1721.     call_rexx(msg_string,&result); /* Ignore the results. */
  1722.     }
  1723.   }
  1724. #endif
  1725.  
  1726. @ There are three types of \.{CWEB} errors reported to the message browser.
  1727. For completeness we give them the numbers~997 to~999.  The first one refers
  1728. to errors in the active change file.  If you click on the error line in the
  1729. browser window, your system editor will take you to the offending line in
  1730. the change file (given the communication between the browser and your
  1731. editor is properly set up).  There is a slight difficulty when entering
  1732. file names into the error message; the browser expects complete path names
  1733. and we have to add them more or less manually.
  1734. @^system dependencies@>
  1735.  
  1736. @<Report an error in the change file@>=
  1737. #ifdef _AMIGA
  1738. if(send_error_messages) {
  1739.   if(GetCurrentDirName(cur_buffer,BUFSIZ) && @|
  1740.     AddPart(cur_buffer,web_file_name,BUFSIZ) && @|
  1741.     GetCurrentDirName(pth_buffer,BUFSIZ) && @|
  1742.     AddPart(pth_buffer,change_file_name,BUFSIZ))
  1743.     sprintf(msg_string,"newmsg \"%s\" \"%s\" %d 0 \"\" 0 Error 997 %s",@|
  1744.       cur_buffer,pth_buffer,change_line,s);
  1745.   }
  1746. #endif
  1747.  
  1748. @ The next type of error occurs in the web file itself, so the current file
  1749. is the same as the offending file.  We have to create the full name only once.
  1750. @^system dependencies@>
  1751.  
  1752. @<Report an error in the web file@>=
  1753. #ifdef _AMIGA
  1754. if(send_error_messages) {
  1755.   if(GetCurrentDirName(cur_buffer,BUFSIZ) && @|
  1756.     AddPart(cur_buffer,cur_file_name,BUFSIZ))
  1757.     sprintf(msg_string,"newmsg \"%s\" \"%s\" %d 0 \"\" 0 Error 998 %s",@|
  1758.       cur_buffer,cur_buffer,cur_line,s);
  1759.   }
  1760. #endif
  1761.  
  1762. @ The error with the highest number is also the most subtle type.  It
  1763. occurs inside an include file, so we have to distinguish between the web
  1764. file and the offending file.
  1765. @^system dependencies@>
  1766.  
  1767. @<Report an error in an include file@>=
  1768. #ifdef _AMIGA
  1769. if(send_error_messages) {
  1770.   strcpy(msg_string,"\0");
  1771.   if(GetCurrentDirName(cur_buffer,BUFSIZ) && @|
  1772.     AddPart(cur_buffer,cur_file_name,BUFSIZ) && @|
  1773.     GetCurrentDirName(pth_buffer,BUFSIZ) && @|
  1774.     AddPart(pth_buffer,web_file_name,BUFSIZ))
  1775.     sprintf(msg_string,"newmsg \"%s\" \"%s\" %d 0 \"\" 0 Error 999 %s",@|
  1776.       pth_buffer,cur_buffer,cur_line,s);
  1777.   }
  1778. #endif
  1779.  
  1780. @ In the three sections above we simply created a string holding the full
  1781. entry line which is handed over to the message browser by calling our
  1782. |call_rexx| routine.  The boolean return value is ignored.
  1783. @^system dependencies@>
  1784.  
  1785. @<Put the error message in the browser@>=
  1786. #ifdef _AMIGA
  1787. if(send_error_messages && msg_string)
  1788.   call_rexx(msg_string,&result); /* Ignore the results. */
  1789. #endif
  1790.  
  1791. @** Function declarations. Here are declarations, conforming to {\mc ANSI~C},
  1792. of all functions in this code that appear in |"common.h"| and thus should
  1793. agree with \.{CTANGLE} and \.{CWEAVE}.
  1794.  
  1795. @<Predecl...@>=
  1796. int get_line(void);@/
  1797. name_pointer add_section_name(name_pointer,int,char *,char *,int);@/
  1798. name_pointer id_lookup(char *,char *,char);@/
  1799. name_pointer section_lookup(char *,char *,int);
  1800. void check_complete(void);@/
  1801. void common_init(void);@/
  1802. void extend_section_name(name_pointer,char *,char *,int);@/
  1803. void print_prefix_name(name_pointer);@/
  1804. void print_section_name(name_pointer);@/
  1805. void reset_input(void);@/
  1806. void sprint_section_name(char *,name_pointer);@/
  1807.  
  1808. @ The following functions are private to |"common.w"|.
  1809.  
  1810. @<Predecl...@>=
  1811. static boolean set_path(char *,char *);@/
  1812. static int input_ln(FILE *);@/
  1813. static int web_strcmp(char HUGE *,int,char HUGE *,int);@/
  1814. static void check_change(void);@/
  1815. static void prime_the_change_buffer(void);@/
  1816.  
  1817. @** Index.
  1818. @z
  1819. ------------------------------------------------------------------------------
  1820.